//
//  TKL_MessageVC.m
//  TKL_EnPro
//
//  Created by 雅恩三河科技 on 2018/12/11.
//  Copyright © 2018年 MrZhang. All rights reserved.
//

//
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                  \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
//
//

#import "TKL_MessageVC.h"

@interface TKL_MessageVC ()
{
    NSInteger currentPage;
}
@property(nonatomic,strong)NSMutableArray* dataSource;
@end

@implementation TKL_MessageVC
-(NSMutableArray *)dataSource
{
    if (!_dataSource) {
        _dataSource=[NSMutableArray new];
    }
    return _dataSource;
}

#pragma mark - event
#pragma mark - method
-(void)initilization
{
    self.isGroup = YES;
    currentPage=1;
    @WeakSelf;
    self.navigationItem.title =@"消息";

    self.extendedLayoutIncludesOpaqueBars = YES;
    self.baseTable.contentInset = UIEdgeInsetsMake([self topShelterHeight], 0, [self bottomShelterHeight], 0);
    self.view.backgroundColor = Main_Color_BG;
    
    [self.view addSubview:self.baseTable];
    [self.baseTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.baseTable setSeparatorColor:Main_Color_BG];
    [self viewModelBand];
    
    
    self.baseTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        currentPage=1;
        [selfp reloadData];
        [selfp.baseTable.mj_header endRefreshing];
    }];
    self.baseTable.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
        
        currentPage+=1;
        [selfp reloadData];
        
        [selfp.baseTable.mj_footer endRefreshing];
    }];
    [selfp reloadData];
}
-(void)viewModelBand
{
    @WeakSelf;

}
-(void)reloadListData
{
    NSMutableDictionary* para=[NSMutableDictionary new];
    
    [para setObject:[NSNumber numberWithInteger:currentPage] forKey:@"page"];
    if (currentPage==1)
    {
        [para setObject:@"0" forKey:@"base"];
    }else
    {
        
        [para setObject:[NSNumber numberWithInteger:[[WFFunctions getStringNow] integerValue]*1000] forKey:@"base"];
    }
    [para setObject:[TKL_LoginViewModel shareInterface].infoModel.uuid forKey:@"userUuid"];

    [self requestCityData:para];
}
-(void)reloadData
{
    [self reloadListData];
}
-(void)reloadView
{
    
}
#pragma mark - life

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initilization];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataSource.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    @WeakSelf;
    
    static NSString* identify=@"PPthreePhonecell";
    UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:identify];
    if (!cell) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identify];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor whiteColor];
    }
    NSDictionary* dic=self.dataSource[indexPath.section];

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSDictionary* dic=self.dataSource[indexPath.section];
    if ([WFFunctions WFStrCheckEmpty:[dic objectForKey:@"images"]])
    {
        return WFCGFloatY(170);
    }
    return WFCGFloatY(270);
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* view=[[UIView alloc] init];
    view.backgroundColor=[UIColor whiteColor];
    
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return .0001f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=Main_Color_BGLightGray;
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return WFCGFloatY(10);
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary* dic=self.dataSource[indexPath.section];
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
}
-(void)requestCityData:(NSMutableDictionary *)para
{
    @WeakSelf;
    //http://101.201.171.131:8080/rest/api/notice/message/list/ 消息列表   base=0&page=1&userUuid=63e5eeec-588a-4c66-9356-ab7b4313a020
    [[InterfaceManager shareInterface] requestAllInterface:@"http://101.201.171.131:8080/rest/api/notice/message/list" para:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        if (currentPage==1)
        {
            [selfp.dataSource removeAllObjects];
        }
        NSArray* arr=[info objectForKey:@"dataList"];
        for (NSDictionary* dic in arr) {
            
            if ([[dic objectForKey:@"longShort"] integerValue]==1)
            {
                [selfp.dataSource addObject:dic];
            }
        }
        [selfp.baseTable reloadData];
    }];
}
@end


/*
 11111111111111111111111111111111111111001111111111111111111111111
 11111111111111111111111111111111111100011111111111111111111111111
 11111111111111111111111111111111100001111111111111111111111111111
 11111111111111111111111111111110000111111111111111111111111111111
 11111111111111111111111111111000000111111111111111111111111111111
 11111111111111111111111111100000011110001100000000000000011111111
 11111111111111111100000000000000000000000000000000011111111111111
 11111111111111110111000000000000000000000000000011111111111111111
 11111111111111111111111000000000000000000000000000000000111111111
 11111111111111111110000000000000000000000000000000111111111111111
 11111111111111111100011100000000000000000000000000000111111111111
 11111111111111100000110000000000011000000000000000000011111111111
 11111111111111000000000000000100111100000000000001100000111111111
 11111111110000000000000000001110111110000000000000111000011111111
 11111111000000000000000000011111111100000000000000011110001111111
 11111110000000011111111111111111111100000000000000001111100111111
 11111111000001111111111111111111110000000000000000001111111111111
 11111111110111111111111111111100000000000000000000000111111111111
 11111111111111110000000000000000000000000000000000000111111111111
 11111111111111111100000000000000000000000000001100000111111111111
 11111111111111000000000000000000000000000000111100000111111111111
 11111111111000000000000000000000000000000001111110000111111111111
 11111111100000000000000000000000000000001111111110000111111111111
 11111110000000000000000000000000000000111111111110000111111111111
 11111100000000000000000001110000001111111111111110001111111111111
 11111000000000000000011111111111111111111111111110011111111111111
 11110000000000000001111111111111111100111111111111111111111111111
 11100000000000000011111111111111111111100001111111111111111111111
 11100000000001000111111111111111111111111000001111111111111111111
 11000000000001100111111111111111111111111110000000111111111111111
 11000000000000111011111111111100011111000011100000001111111111111
 11000000000000011111111111111111000111110000000000000011111111111
 11000000000000000011111111111111000000000000000000000000111111111
 11001000000000000000001111111110000000000000000000000000001111111
 11100110000000000001111111110000000000000000111000000000000111111
 11110110000000000000000000000000000000000111111111110000000011111
 11111110000000000000000000000000000000001111111111111100000001111
 11111110000010000000000000000001100000000111011111111110000001111
 11111111000111110000000000000111110000000000111111111110110000111
 11111110001111111100010000000001111100000111111111111111110000111
 11111110001111111111111110000000111111100000000111111111111000111
 11111111001111111111111111111000000111111111111111111111111100011
 11111111101111111111111111111110000111111111111111111111111001111
 11111111111111111111111111111110001111111111111111111111100111111
 11111111111111111111111111111111001111111111111111111111001111111
 11111111111111111111111111111111100111111111111111111111111111111
 11111111111111111111111111111111110111111111111111111111111111111
 
 
 */
